package com.zhangsun;

import com.zhangsun.read.ReadWeb;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class WebToText {

    public static void main(String[] args) {
        try {
            File htmlFile = new File("E:\\html");
            File[] files = htmlFile.listFiles();
            if (files != null && files.length > 0) {
                for (File file : files) {
                    if (file.listFiles() == null || file.listFiles().length == 0) {
                        continue;
                    }
                    File txtFile = new File("E:\\text", file.getName() + ".txt");
                    if (!txtFile.exists()) {
                        txtFile.createNewFile();
                    }
                    try (FileWriter writer = new FileWriter(txtFile);
                         BufferedWriter out = new BufferedWriter(writer)) {
                        ReadWeb.newInstance(file, out).readWeb();
                        out.flush();
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
